﻿using TribesPSO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;

namespace TribesPSOTest
{
    
    
    /// <summary>
    ///This is a test class for ExtensionsTest and is intended
    ///to contain all ExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ExtensionsTest
    {

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Split
        ///</summary>
        public void SplitTestHelper<T>()
        {
            List<T> backing = new List<T>();
            for (int n = 0; n < 10; n++)
            {
                backing.Add(default(T));
            }
            IEnumerable<T> ToSplit = backing;
            int targetSplitInterval = 6;
            
            IEnumerable<IEnumerable<T>> actual;
            actual = Extensions.Split<T>(ToSplit, targetSplitInterval);

            Assert.AreEqual(6,actual.ElementAt(0).Count());
            Assert.AreEqual(4,actual.ElementAt(1).Count());
        }

        public void IntSplitTestHelper()
        {
            List<int> backing = new List<int>();
            for (int n = 0; n < 10; n++)
            {
                backing.Add(n);
            }
            IEnumerable<int> ToSplit = backing;
            int targetSplitInterval = 6;

            IEnumerable<IEnumerable<int>> actual;
            actual = Extensions.Split<int>(ToSplit, targetSplitInterval);

            Assert.AreEqual(6, actual.ElementAt(0).Count());
            Assert.AreEqual(4, actual.ElementAt(1).Count());

            actual = ToSplit.Split(5);
            Assert.AreEqual(5, actual.ElementAt(0).Count());
            Assert.AreEqual(5, actual.ElementAt(1).Count());
        }

        [TestMethod()]
        public void SplitTest()
        {
            IntSplitTestHelper();
            SplitTestHelper<object>();
        }
    }
}
